Backbone.View.extend.postRender   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
c 2
b 0
f 0
nc 2
nop 2
dl 0
loc 6
rs 9.4285
1
import Backbone from 'backbone';
0 ignored issues
show
introduced by
Definition for rule 'keyword-spacing' was not found
Loading history...
2
3
import {
4
  Column
5
} from '../column.js';
6
/*
7
  backgrid
8
  http://github.com/wyuenho/backgrid
9
10
  Copyright (c) 2013 Jimmy Yuen Ho Wong and contributors
11
  Licensed under the MIT license.
12
*/
13
14
/**
15
   Generic cell editor base class. Only defines an initializer for a number of
16
   required parameters.
17
18
   @abstract
19
   @class Backgrid.CellEditor
20
   @extends Backbone.View
21
*/
22
var CellEditor = Backbone.View.extend({
23
24
  /**
25
     Initializer.
26
27
     @param {Object} options
28
     @param {Backgrid.CellFormatter} options.formatter
29
     @param {Backgrid.Column} options.column
30
     @param {Backbone.Model} options.model
31
32
     @throws {TypeError} If `formatter` is not a formatter instance, or when
33
     `model` or `column` are undefined.
34
  */
35
  initialize: function (options) {
36
    this.formatter = options.formatter;
37
    this.column = options.column;
38
    if (!(this.column instanceof Column)) {
39
      this.column = new Column(this.column);
40
    }
41
42
    this.listenTo(this.model, "backgrid:editing", this.postRender);
43
  },
44
45
  /**
46
     Post-rendering setup and initialization. Focuses the cell editor's `el` in
47
     this default implementation. **Should** be called by Cell classes after
48
     calling Backgrid.CellEditor#render.
49
  */
50
  postRender: function (model, column) {
51
    if (column == null || column.get("name") == this.column.get("name")) {
0 ignored issues
show
introduced by
Use ‘===’ to compare with ‘null’.
Loading history...
Bug Best Practice introduced by
Apart from some edge-cases, it is generally advisable to use the strict comparison === instead of ==.

The loose comparison such as == or != might produce some weird results for some values, unless you explicitly want to have this behavior here, better use the strict alternative.

Learn more about loose comparison in Javascript.

Loading history...
52
      this.$el.focus();
53
    }
54
    return this;
55
  }
56
57
});
58
export {
59
  CellEditor
60
};
61